package leetcode;

public class LeetCode206 {
    // 头插法
    public ListNode reverseList1(ListNode head) {
        ListNode newHead = null, p = head, tmp;
        while (p != null) {
            tmp = p;
            p = p.next;
            tmp.next = newHead;
            newHead = tmp;
        }
        return newHead;
    }

    //递归版
    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null)
            return head;
        ListNode temp = head.next;
        ListNode newHead = reverseList(head.next);
        temp.next = head;
        head.next = null;
        return newHead;
    }
}
